In [56]:
import numpy as np
import pandas as pd
import os
btc = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/bitcoin_price.csv')
eth = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/ethereum_price.csv')
ripple = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/ripple_price.csv')
monero = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/monero_price.csv')
dash = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/dash_price.csv')
litecoin = pd.read_csv('/Users/oj/Desktop/PythonProjectCrypto/CryptoData/litecoin_price.csv')
In [57]:
def req_data(coindb):
coindb = coindb.loc[:,['Date','Close']] #Only working with Closing values for this study
coindb['Date'] = pd.to_datetime(coindb['Date'])
return coindb
btc_req_data = pd.DataFrame(req_data(btc))
eth_req_data = pd.DataFrame(req_data(eth))
ripple_req_data = pd.DataFrame(req_data(ripple))
monero_req_data = pd.DataFrame(req_data(monero))
dash_req_data = pd.DataFrame(req_data(dash))
litecoin_req_data = pd.DataFrame(req_data(litecoin))
btc_req_data
#eth_req_data
#ripple_req_data
#monero_req_data
#dash_req_data
#litecoin_req_data
Out[57]:
In [58]:
# Historical prices
import matplotlib.pyplot as plt
def plot_data(coindb, name):
plt.figure(figsize=(16,6))
x = coindb['Date']
y = coindb['Close']
plt.xlabel('Timeline')
plt.ylabel(name)
plt.plot(x,y,'--')
_ = plt.xticks(rotation=45)
plt.show()
plot_data(btc_req_data, 'Bitcoin Closing Values')
plot_data(eth_req_data, 'Ethereum Closing Values')
plot_data(ripple_req_data, 'Ripple Closing Values')
plot_data(monero_req_data, 'Monero Closing Values')
plot_data(dash_req_data, 'Dash Closing Values')
plot_data(litecoin_req_data, 'Litecoin Closing Values')
OBSERVATIONS:
1. For the given time frame, it is observed that there has been a sudden surge in
the closing prices of the cryptocurrencies
In [59]:
# import seaborn as sns
New_dataSet = pd.DataFrame()
New_dataSet['Bitcoin Closing Price'] = btc_req_data['Close']
New_dataSet['Ethereum Closing Price'] = eth_req_data['Close']
New_dataSet['Ripple Closing Price'] = ripple_req_data['Close']
New_dataSet['Monero Closing Price'] = monero_req_data['Close']
New_dataSet['Dash Closing Price'] = dash_req_data['Close']
New_dataSet['Litecoin Closing Price'] = litecoin_req_data['Close']
New_dataSet.fillna(0, inplace=True)
New_dataSet
Out[59]:
In [60]:
New_dataSet = New_dataSet.iloc[::-1]
mx = New_dataSet.plot(figsize=(20,16))
mx.set_xlabel("Time")
mx.set_ylabel("Closing Prices")
plt.show()
In [61]:
Norm_New_dataSet = pd.DataFrame()
Norm_New_dataSet
Norm_New_dataSet['Norm Bitcoin Closing Price'] = New_dataSet['Bitcoin Closing Price']/New_dataSet['Bitcoin Closing Price'].mean()
Norm_New_dataSet['Norm Ethereum Closing Price'] = New_dataSet['Ethereum Closing Price']/New_dataSet['Ethereum Closing Price'].mean()
Norm_New_dataSet['Norm Ripple Closing Price'] = New_dataSet['Ripple Closing Price']/New_dataSet['Ripple Closing Price'].mean()
Norm_New_dataSet['Norm Monero Closing Price'] = New_dataSet['Monero Closing Price']/New_dataSet['Monero Closing Price'].mean()
Norm_New_dataSet['Norm Dash Closing Price'] = New_dataSet['Dash Closing Price']/New_dataSet['Dash Closing Price'].mean()
Norm_New_dataSet['Norm Litecoin Closing Price'] = New_dataSet['Litecoin Closing Price']/New_dataSet['Litecoin Closing Price'].mean()
Norm_New_dataSet = Norm_New_dataSet[::-1]
Norm_New_dataSet
Out[61]:
In [62]:
ax = Norm_New_dataSet[::-1].plot(figsize=(20,16))
ax.set_xlabel("Time")
ax.set_ylabel("Normalized Closing values")
plt.show()
In [63]:
import statistics
lst=[]
coindbdict = {'Bitcoin': btc_req_data, 'Ethereum': eth_req_data, 'Ripple': ripple_req_data, 'Monero':monero_req_data,'Dash':dash_req_data,'Litecoin':litecoin_req_data}
def Var_Coeff(coindb, name):
mean = coindb['Close'].mean()
#print(mean)
std_dev = statistics.stdev(coindb['Close'])
coeff_var = round((std_dev/mean),5)
return coeff_var, name
for key in coindbdict:
lst.append(Var_Coeff(coindbdict[key], key))
lst.sort()
# print(lst)
print("Most Stable coin / Least volatile crypto-currency, for the given dataset is:",min(lst)[1].upper(),"with a variance coeff of",min(lst)[0])
print("Least Stable coin / Most volatile crypto-currency, for the given dataset is:",max(lst)[1].upper(),"with a variance coeff of",max(lst)[0])
In [64]:
New_dataSet_Corr = pd.DataFrame()
New_dataSet_Corr['Bitcoin Closing Price'] = btc_req_data['Close']
New_dataSet_Corr['Ethereum Closing Price'] = eth_req_data['Close']
New_dataSet_Corr['Ripple Closing Price'] = ripple_req_data['Close']
New_dataSet_Corr['Monero Closing Price'] = monero_req_data['Close']
New_dataSet_Corr['Dash Closing Price'] = dash_req_data['Close']
New_dataSet_Corr['Litecoin Closing Price'] = litecoin_req_data['Close']
#New_dataSet
New_dataSet_Corr.fillna(0, inplace=True)
x = New_dataSet_Corr.pct_change().corr(method='pearson')
x
Out[64]:
In [65]:
plt.subplots(figsize=(10,10))
plt.xticks(range(6), x.columns.values, rotation='vertical')
plt.yticks(range(6), x.columns.values)
plt.xlabel('CryptoCurrency Correlation')
heat = plt.imshow(x, cmap="hot")#, figsize=(20,16))
plt.colorbar(heat)
plt.show()
In [77]:
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets, linear_model
from sklearn.metrics import mean_squared_error, r2_score
import pandas as pd
def TestData(coindb):
X = coindb['Date'].reset_index(drop=True)
Y = coindb['Close'].reset_index(drop=True)
#print(X)
#print(Y)
m=(len(coindb)//4)*3
n=len(coindb)//4
X=X.values.reshape(len(X),1)
Y=Y.values.reshape(len(Y),1)
# Split the data into training/testing sets
X_train = X[:m]
X_test = X[m:len(X)]
# Split the targets into training/testing sets
Y_train = Y[:m]
Y_test = Y[m:len(X)]
return X_test,X_train,Y_test,Y_train
In [105]:
def linear_reg(df):
df = df[::-1]
X_test,X_train,Y_test,Y_train=TestData(df)
plt.scatter(X_test, Y_test, color='black',s=3)
plt.title('Test Data')
plt.xlabel('Date')
plt.ylabel('Close Price')
plt.xticks(())
plt.yticks(())
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(X_train, Y_train)
plt.plot(X_test, regr.predict(Y_test), color='red',linewidth=3)
plt.show()
linear_reg(btc_req_data)